<template>
  <div id="app">
    <Topbar :key="topbarkey"></Topbar>
    <Header></Header>
    <router-view @updateKey="updateKeyFn" />
    <Footer></Footer>
    <Login v-show="isShowLoginModal"></Login>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>
<script>
import Topbar from "./components/Topbar.vue";
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import Login from "./components/Login.vue";
import Toast from "./components/Toast.vue";
import { JingPinAPI, ReMenAPI } from "@/request/api.js";
import { mapState } from "vuex";
export default {
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast,
  },
  data() {
    return {
      topbarkey: 0,
    };
  },
  async created() {
    // console.log("请求数据");
    /* //在学校： http://192.168.113.249:8081/cms
    //在家：   http://kumanxuan1.f3322.net:8881/cms
    //学会检查network , 核对请求地址,请求方式，请求参数，响应结果。
    axios
      .get("http://kumanxuan1.f3322.net:8881/cms/products/recommend")
      .then((res) => {
        console.log(res);
      }); */
    /* axios.get("/products/recommend").then((res) => {
      console.log(res);
    }); */
    /* JingPinAPI().then((res) => {
      console.log("1:", res);
    });
    console.log("2:");
    ReMenAPI().then((res)=>{
      console.log("3",res);
    })
    console.log("4:"); */
    /* let res = await JingPinAPI();
    console.log("1:", res);
    console.log("2:");
    let res2 = await ReMenAPI();
    console.log("3:", res2);
    console.log("4:"); */
    
    console.log("环境变量为：",process.env.VUE_APP_BASE_URL);
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast,
    }),
  },
  methods: {
    updateKeyFn() {
      console.log("App收到通知了");
      this.topbarkey++;
    },
  },
  watch: {
    "$route.path": {
      handler(newVal, oldVal) {
        console.log("地址变化了");
        if (oldVal != "/") {
          this.topbarkey++;
        }
      },
    },
  },
};
</script>
<style lang="less">
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter,
.slide-leave-to {
  opacity: 0;
}

.slide-enter-active,
.slide-leave-active {
  transition: opacity 0.3s linear;
}

.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
